package ProducerConsumerModel;

public class ProducerConsumer {
    public static void main(String[] args) {
        Desk desk = new Desk(1);
            //生产者线程1
            Thread thread1 = new Thread(()->{
                try {
                    while (true) {
                        desk.put("华为电脑");
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"生产者1");
            thread1.start();
            //生产者线程2
            Thread thread2 = new Thread(()->{
                try {
                    while (true) {
                        desk.put("小米su7");
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"生产者2");
            thread2.start();

            //生产者线程3
            Thread thread3 = new Thread(()->{
                try {
                    while (true) {
                        desk.put("大疆无人机");
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"生产者3");
            thread3.start();

            //消费者1
            Thread thread4 = new Thread(()->{
                try {
                    while (true) {
                        desk.take();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"消费者1");
            thread4.start();

            //消费者2
            Thread thread5 = new Thread(()->{
                try {
                    while (true) {
                        desk.take();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"消费者2");
            thread5.start();
    }
}
